﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 员工续签增加文件支持多附件 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysHrRenewRequestBill_FileAttachments_ContractFileId",
                table: "SysHrRenewRequestBill");

            migrationBuilder.DropIndex(
                name: "IX_SysHrRenewRequestBill_ContractFileId",
                table: "SysHrRenewRequestBill");

            migrationBuilder.DropColumn(
                name: "ContractFileId",
                table: "SysHrRenewRequestBill");

            migrationBuilder.CreateTable(
                name: "SysHrRenewContractFile",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    HrRenewRequestBillId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    FileId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Order = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysHrRenewContractFile", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysHrRenewContractFile_FileAttachments_FileId",
                        column: x => x.FileId,
                        principalTable: "FileAttachments",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_SysHrRenewContractFile_SysHrRenewRequestBill_HrRenewRequestBillId",
                        column: x => x.HrRenewRequestBillId,
                        principalTable: "SysHrRenewRequestBill",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysHrRenewContractFile_FileId",
                table: "SysHrRenewContractFile",
                column: "FileId");

            migrationBuilder.CreateIndex(
                name: "IX_SysHrRenewContractFile_HrRenewRequestBillId",
                table: "SysHrRenewContractFile",
                column: "HrRenewRequestBillId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SysHrRenewContractFile");

            migrationBuilder.AddColumn<Guid>(
                name: "ContractFileId",
                table: "SysHrRenewRequestBill",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_SysHrRenewRequestBill_ContractFileId",
                table: "SysHrRenewRequestBill",
                column: "ContractFileId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysHrRenewRequestBill_FileAttachments_ContractFileId",
                table: "SysHrRenewRequestBill",
                column: "ContractFileId",
                principalTable: "FileAttachments",
                principalColumn: "ID",
                onDelete: ReferentialAction.Restrict);
        }
    }
}
